<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>API: yahoo   Env.js  (YUI Library)</title>
	<link rel="stylesheet" type="text/css" href="assets/api.css">
    <script type="text/javascript" src="assets/api-js"></script>
    <script type="text/javascript" src="assets/ac-js"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">

	<div id="hd">
        <a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
        <h3>YAHOO Global&nbsp; <span class="subtitle">2.3.1</span></h3>
        <p>
        <a href="./index.html">Yahoo! UI Library</a> 
            &gt; <a href="./module_yahoo.html">yahoo</a>
                
                 &gt; Env.js (source view) 
            </p>

	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form name="yui-classopts-form">
    <span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
    <span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 #classopts { display:none; }
                        </style>
<div class="highlight" ><pre><span class="c">/**</span>
<span class="c"> * YAHOO.env is used to keep track of what is known about the YUI library and</span>
<span class="c"> * the browsing environment</span>
<span class="c"> * @class YAHOO.env</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span> <span class="o">=</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span> <span class="o">||</span> <span class="o">{</span>

    <span class="c">/**</span>
<span class="c">     * Keeps the version info for all YUI modules that have reported themselves</span>
<span class="c">     * @property modules</span>
<span class="c">     * @type Object[]</span>
<span class="c">     */</span>
    <span class="nx">modules</span><span class="o">:</span> <span class="o">[],</span>
    
    <span class="c">/**</span>
<span class="c">     * List of functions that should be executed every time a YUI module</span>
<span class="c">     * reports itself.</span>
<span class="c">     * @property listeners</span>
<span class="c">     * @type Function[]</span>
<span class="c">     */</span>
    <span class="nx">listeners</span><span class="o">:</span> <span class="o">[]</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Returns the version data for the specified module:</span>
<span class="c"> *      &lt;dl&gt;</span>
<span class="c"> *      &lt;dt&gt;name:&lt;/dt&gt;      &lt;dd&gt;The name of the module&lt;/dd&gt;</span>
<span class="c"> *      &lt;dt&gt;version:&lt;/dt&gt;   &lt;dd&gt;The version in use&lt;/dd&gt;</span>
<span class="c"> *      &lt;dt&gt;build:&lt;/dt&gt;     &lt;dd&gt;The build number in use&lt;/dd&gt;</span>
<span class="c"> *      &lt;dt&gt;versions:&lt;/dt&gt;  &lt;dd&gt;All versions that were registered&lt;/dd&gt;</span>
<span class="c"> *      &lt;dt&gt;builds:&lt;/dt&gt;    &lt;dd&gt;All builds that were registered.&lt;/dd&gt;</span>
<span class="c"> *      &lt;dt&gt;mainClass:&lt;/dt&gt; &lt;dd&gt;An object that was was stamped with the</span>
<span class="c"> *                 current version and build. If </span>
<span class="c"> *                 mainClass.VERSION != version or mainClass.BUILD != build,</span>
<span class="c"> *                 multiple versions of pieces of the library have been</span>
<span class="c"> *                 loaded, potentially causing issues.&lt;/dd&gt;</span>
<span class="c"> *       &lt;/dl&gt;</span>
<span class="c"> *</span>
<span class="c"> * @method getVersion</span>
<span class="c"> * @static</span>
<span class="c"> * @param {String}  name the name of the module (event, slider, etc)</span>
<span class="c"> * @return {Object} The version info</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span><span class="o">.</span><span class="nx">getVersion</span> <span class="o">=</span> <span class="k">function</span><span class="o">(</span><span class="nx">name</span><span class="o">)</span> <span class="o">{</span>
    <span class="k">return</span> <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span><span class="o">.</span><span class="nx">modules</span><span class="o">[</span><span class="nx">name</span><span class="o">]</span> <span class="o">||</span> <span class="kc">null</span><span class="o">;</span>
<span class="o">};</span>

<span class="c">/**</span>
<span class="c"> * Do not fork for a browser if it can be avoided.  Use feature detection when</span>
<span class="c"> * you can.  Use the user agent as a last resort.  YAHOO.env.ua stores a version</span>
<span class="c"> * number for the browser engine, 0 otherwise.  This value may or may not map</span>
<span class="c"> * to the version number of the browser using the engine.  The value is </span>
<span class="c"> * presented as a float so that it can easily be used for boolean evaluation </span>
<span class="c"> * as well as for looking for a particular range of versions.  Because of this, </span>
<span class="c"> * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9 </span>
<span class="c"> * reports 1.8).</span>
<span class="c"> * @class YAHOO.env.ua</span>
<span class="c"> * @static</span>
<span class="c"> */</span>
<span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span><span class="o">.</span><span class="nx">ua</span> <span class="o">=</span> <span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="k">var</span> <span class="nx">o</span><span class="o">={</span>

        <span class="c">/**</span>
<span class="c">         * Internet Explorer version number or 0.  Example: 6</span>
<span class="c">         * @property ie</span>
<span class="c">         * @type float</span>
<span class="c">         */</span>
        <span class="nx">ie</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>

        <span class="c">/**</span>
<span class="c">         * Opera version number or 0.  Example: 9.2</span>
<span class="c">         * @property opera</span>
<span class="c">         * @type float</span>
<span class="c">         */</span>
        <span class="nx">opera</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>

        <span class="c">/**</span>
<span class="c">         * Gecko engine revision number.  Will evaluate to 1 if Gecko </span>
<span class="c">         * is detected but the revision could not be found. Other browsers</span>
<span class="c">         * will be 0.  Example: 1.8</span>
<span class="c">         * &lt;pre&gt;</span>
<span class="c">         * Firefox 1.0.0.4: 1.7.8   &lt;-- Reports 1.7</span>
<span class="c">         * Firefox 1.5.0.9: 1.8.0.9 &lt;-- Reports 1.8</span>
<span class="c">         * Firefox 2.0.0.3: 1.8.1.3 &lt;-- Reports 1.8</span>
<span class="c">         * Firefox 3 alpha: 1.9a4   &lt;-- Reports 1.9</span>
<span class="c">         * &lt;/pre&gt;</span>
<span class="c">         * @property gecko</span>
<span class="c">         * @type float</span>
<span class="c">         */</span>
        <span class="nx">gecko</span><span class="o">:</span><span class="m">0</span><span class="o">,</span>

        <span class="c">/**</span>
<span class="c">         * AppleWebKit version.  KHTML browsers that are not WebKit browsers </span>
<span class="c">         * will evaluate to 1, other browsers 0.  Example: 418.9.1</span>
<span class="c">         * &lt;pre&gt;</span>
<span class="c">         * Safari 1.3.2 (312.6): 312.8.1 &lt;-- Reports 312.8 -- currently the </span>
<span class="c">         *                                   latest available for Mac OSX 10.3.</span>
<span class="c">         * Safari 2.0.2:         416     &lt;-- hasOwnProperty introduced</span>
<span class="c">         * Safari 2.0.4:         418     &lt;-- preventDefault fixed</span>
<span class="c">         * Safari 2.0.4 (419.3): 418.9.1 &lt;-- One version of Safari may run</span>
<span class="c">         *                                   different versions of webkit</span>
<span class="c">         * Safari 2.0.4 (419.3): 419     &lt;-- Current Safari release</span>
<span class="c">         * Webkit 212 nightly:   522+    &lt;-- Safari 3.0 (with native SVG) should</span>
<span class="c">         *                                   be higher than this</span>
<span class="c">         *                                   </span>
<span class="c">         * &lt;/pre&gt;</span>
<span class="c">         * http://developer.apple.com/internet/safari/uamatrix.html</span>
<span class="c">         * @property webkit</span>
<span class="c">         * @type float</span>
<span class="c">         */</span>
        <span class="nx">webkit</span><span class="o">:</span><span class="m">0</span>
    <span class="o">};</span>

    <span class="k">var</span> <span class="nx">ua</span><span class="o">=</span><span class="nx">navigator</span><span class="o">.</span><span class="nx">userAgent</span><span class="o">,</span> <span class="nx">m</span><span class="o">;</span>

    <span class="c">// Modern KHTML browsers should qualify as Safari X-Grade</span>
<span class="c"></span>    <span class="k">if</span> <span class="o">((</span><span class="sr">/KHTML/</span><span class="o">).</span><span class="nx">test</span><span class="o">(</span><span class="nx">ua</span><span class="o">))</span> <span class="o">{</span>
        <span class="nx">o</span><span class="o">.</span><span class="nx">webkit</span><span class="o">=</span><span class="m">1</span><span class="o">;</span>
    <span class="o">}</span>
    <span class="c">// Modern WebKit browsers are at least X-Grade</span>
<span class="c"></span>    <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/AppleWebKit\/([^\s]*)/</span><span class="o">);</span>
    <span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">&amp;&amp;</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">])</span> <span class="o">{</span>
        <span class="nx">o</span><span class="o">.</span><span class="nx">webkit</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
    <span class="o">}</span>

    <span class="k">if</span> <span class="o">(!</span><span class="nx">o</span><span class="o">.</span><span class="nx">webkit</span><span class="o">)</span> <span class="o">{</span> <span class="c">// not webkit</span>
<span class="c"></span>        <span class="c">// @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)</span>
<span class="c"></span>        <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/Opera[\s\/]([^\s]*)/</span><span class="o">);</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">&amp;&amp;</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">])</span> <span class="o">{</span>
            <span class="nx">o</span><span class="o">.</span><span class="nx">opera</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
        <span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// not opera or webkit</span>
<span class="c"></span>            <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/MSIE\s([^;]*)/</span><span class="o">);</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">&amp;&amp;</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">])</span> <span class="o">{</span>
                <span class="nx">o</span><span class="o">.</span><span class="nx">ie</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
            <span class="o">}</span> <span class="k">else</span> <span class="o">{</span> <span class="c">// not opera, webkit, or ie</span>
<span class="c"></span>                <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/Gecko\/([^\s]*)/</span><span class="o">);</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">o</span><span class="o">.</span><span class="nx">gecko</span><span class="o">=</span><span class="m">1</span><span class="o">;</span> <span class="c">// Gecko detected, look for revision</span>
<span class="c"></span>                    <span class="nx">m</span><span class="o">=</span><span class="nx">ua</span><span class="o">.</span><span class="nx">match</span><span class="o">(</span><span class="sr">/rv:([^\s\)]*)/</span><span class="o">);</span>
                    <span class="k">if</span> <span class="o">(</span><span class="nx">m</span><span class="o">&amp;&amp;</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">])</span> <span class="o">{</span>
                        <span class="nx">o</span><span class="o">.</span><span class="nx">gecko</span><span class="o">=</span><span class="nb">parseFloat</span><span class="o">(</span><span class="nx">m</span><span class="o">[</span><span class="m">1</span><span class="o">]);</span>
                    <span class="o">}</span>
                <span class="o">}</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">}</span>
    
    <span class="k">return</span> <span class="nx">o</span><span class="o">;</span>
<span class="o">}();</span>

<span class="c">/*</span>
<span class="c"> * Initializes the global by creating the default namespaces and applying</span>
<span class="c"> * any new configuration information that is detected.  This is the setup</span>
<span class="c"> * for env.</span>
<span class="c"> * @method init</span>
<span class="c"> * @static</span>
<span class="c"> * @private</span>
<span class="c"> */</span>
<span class="o">(</span><span class="k">function</span><span class="o">()</span> <span class="o">{</span>
    <span class="nx">YAHOO</span><span class="o">.</span><span class="nx">namespace</span><span class="o">(</span><span class="s2">&quot;util&quot;</span><span class="o">,</span> <span class="s2">&quot;widget&quot;</span><span class="o">,</span> <span class="s2">&quot;example&quot;</span><span class="o">);</span>
    <span class="k">if</span> <span class="o">(</span><span class="s2">&quot;undefined&quot;</span> <span class="o">!==</span> <span class="k">typeof</span> <span class="nx">YAHOO_config</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">var</span> <span class="nx">l</span><span class="o">=</span><span class="nx">YAHOO_config</span><span class="o">.</span><span class="nx">listener</span><span class="o">,</span><span class="nx">ls</span><span class="o">=</span><span class="nx">YAHOO</span><span class="o">.</span><span class="nx">env</span><span class="o">.</span><span class="nx">listeners</span><span class="o">,</span><span class="nx">unique</span><span class="o">=</span><span class="kc">true</span><span class="o">,</span><span class="nx">i</span><span class="o">;</span>
        <span class="k">if</span> <span class="o">(</span><span class="nx">l</span><span class="o">)</span> <span class="o">{</span>
            <span class="c">// if YAHOO is loaded multiple times we need to check to see if</span>
<span class="c"></span>            <span class="c">// this is a new config object.  If it is, add the new component</span>
<span class="c"></span>            <span class="c">// load listener to the stack</span>
<span class="c"></span>            <span class="k">for</span> <span class="o">(</span><span class="nx">i</span><span class="o">=</span><span class="m">0</span><span class="o">;</span><span class="nx">i</span><span class="o">&lt;</span><span class="nx">ls</span><span class="o">.</span><span class="nx">length</span><span class="o">;</span><span class="nx">i</span><span class="o">=</span><span class="nx">i</span><span class="o">+</span><span class="m">1</span><span class="o">)</span> <span class="o">{</span>
                <span class="k">if</span> <span class="o">(</span><span class="nx">ls</span><span class="o">[</span><span class="nx">i</span><span class="o">]==</span><span class="nx">l</span><span class="o">)</span> <span class="o">{</span>
                    <span class="nx">unique</span><span class="o">=</span><span class="kc">false</span><span class="o">;</span>
                    <span class="k">break</span><span class="o">;</span>
                <span class="o">}</span>
            <span class="o">}</span>
            <span class="k">if</span> <span class="o">(</span><span class="nx">unique</span><span class="o">)</span> <span class="o">{</span>
                <span class="nx">ls</span><span class="o">.</span><span class="nx">push</span><span class="o">(</span><span class="nx">l</span><span class="o">);</span>
            <span class="o">}</span>
        <span class="o">}</span>
    <span class="o">}</span>
<span class="o">})();</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div class="module">
                        <h4>Modules</h4>
                        <ul class="content">

                                <li class=""><a href="module_animation.html">animation</a></li>

                                <li class=""><a href="module_autocomplete.html">autocomplete</a></li>

                                <li class=""><a href="module_button.html">button</a></li>

                                <li class=""><a href="module_calendar.html">calendar</a></li>

                                <li class=""><a href="module_colorpicker.html">colorpicker</a></li>

                                <li class=""><a href="module_connection.html">connection</a></li>

                                <li class=""><a href="module_container.html">container</a></li>

                                <li class=""><a href="module_datasource.html">datasource</a></li>

                                <li class=""><a href="module_datatable.html">datatable</a></li>

                                <li class=""><a href="module_dom.html">dom</a></li>

                                <li class=""><a href="module_dragdrop.html">dragdrop</a></li>

                                <li class=""><a href="module_editor.html">editor</a></li>

                                <li class=""><a href="module_element.html">element</a></li>

                                <li class=""><a href="module_event.html">event</a></li>

                                <li class=""><a href="module_history.html">history</a></li>

                                <li class=""><a href="module_imageloader.html">imageloader</a></li>

                                <li class=""><a href="module_logger.html">logger</a></li>

                                <li class=""><a href="module_menu.html">menu</a></li>

                                <li class=""><a href="module_slider.html">slider</a></li>

                                <li class=""><a href="module_tabview.html">tabview</a></li>

                                <li class=""><a href="module_treeview.html">treeview</a></li>

                                <li class="selected"><a href="module_yahoo.html">yahoo</a></li>

                                <li class=""><a href="module_yuiloader.html">yuiloader</a></li>

                                <li class=""><a href="module_yuitest.html">yuitest</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="YAHOO.html">YAHOO</a></li>
                                <li class=""><a href="YAHOO.env.html">YAHOO.env</a></li>
                                <li class=""><a href="YAHOO.env.ua.html">YAHOO.env.ua</a></li>
                                <li class=""><a href="YAHOO.lang.html">YAHOO.lang</a></li>
                                <li class=""><a href="YAHOO_config.html">YAHOO_config</a></li>
                        </ul>
                    </div>

                    <div class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class="selected"><a href="Env.js.html">Env.js</a></li>
                                <li class=""><a href="Lang.js.html">Lang.js</a></li>
                                <li class=""><a href="YAHOO.js.html">YAHOO.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
	</div>
</div>
</body>
</html>
